export default class Bullets extends Laya.Script {

    constructor() { super(); }
    /** @prop {name:dropBox,tips:"掉落容器预制体对象",type:Prefab}*/
    dropBox: Laya.Prefab;
    /** @prop {name:createBoxInterval,tips:"间隔多少毫秒创建一个下跌的容器",type:int,default:1000}*/
    createBoxInterval: number = 3000;
    /**开始时间*/
    private _time: number = 0;
    /**子弹和盒子所在的容器对象 */
    private _gameBox: Laya.Sprite;

    onEnable(): void {
        this._time = Date.now();
        this._gameBox = this.owner.getChildByName("bullets_5") as Laya.Sprite;
    }

    onUpdate(): void {
        //每间隔一段时间创建一个盒子
        let now = Date.now();
        if (now - this._time > 2000) {
            this._time = now;
            this.createBox();
        }
    }


    createBox(): void {
        //使用对象池创建盒子
        let box1: Laya.Sprite = Laya.Pool.getItemByCreateFun("dropBox", this.dropBox.create, this.dropBox);
        let box2: Laya.Sprite = Laya.Pool.getItemByCreateFun("dropBox", this.dropBox.create, this.dropBox);
        let box3: Laya.Sprite = Laya.Pool.getItemByCreateFun("dropBox", this.dropBox.create, this.dropBox);
        let box4: Laya.Sprite = Laya.Pool.getItemByCreateFun("dropBox", this.dropBox.create, this.dropBox);
        let box5: Laya.Sprite = Laya.Pool.getItemByCreateFun("dropBox", this.dropBox.create, this.dropBox);
        let box6: Laya.Sprite = Laya.Pool.getItemByCreateFun("dropBox", this.dropBox.create, this.dropBox);
        box1.pos(185, 40);
        box2.pos(265, 40);
        box3.pos(350, 40);
        box4.pos(904, 40);
        box5.pos(988, 40);
        box6.pos(1071, 40);
        this._gameBox.addChild(box1);
        this._gameBox.addChild(box2);
        this._gameBox.addChild(box3);
        this._gameBox.addChild(box4);
        this._gameBox.addChild(box5);
        this._gameBox.addChild(box6);
    }

    onDisable(): void {
    }
}